home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
usr (gcc 1.37 libs)
/
mac
/
crtlocal.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-10
|
3KB
|
146 lines
#include <fcntl.h>
#include <sys/syslimits.h>
#include <string.h>
#include "crtlocal.h"
#include <Events.h>
struct crt_fd_tab crt_fd_tab[OPEN_MAX+1];
char crt_defpath[255];
short crt_ioVRefNum;
WindowPtr crt_myWindow;
TEHandle crt_TEH;
int crt_sizeof_qd = sizeof(qd);
static char *default_environ[] = {"LOGNAME=jrrk",NULL};
char **environ = default_environ;
int _fmode = O_BINARY;
void mysleep(long t)
{
EventRecord event;
static long oldtemps;
long temps = TickCount() - oldtemps;
if ((temps < 0) || (temps >= 120))
{
WaitNextEvent(0x0, &event, t, NULL);
oldtemps += temps;
}
}
int getdtablesize(void)
{
mysleep(1);
return OPEN_MAX;
}
int getpagesize(void)
{
mysleep(1);
return 8192;
}
void macgetwd(void)
{
VolumeParam pb;
OSErr err;
CInfoPBRec cPB;
cPB.dirInfo.ioDrParID = 0;
pb.ioNamePtr = (StringPtr) crt_defpath;
PBGetVolSync((ParmBlkPtr)&pb);
crt_ioVRefNum = pb.ioVRefNum;
crt_defpath[0] = 0;
do
{
char tmp[256];
strcpy(tmp,crt_defpath);
/* get information about dir */
cPB.hFileInfo.ioCompletion = (ProcPtr)0L;
cPB.hFileInfo.ioNamePtr = (StringPtr)crt_defpath;
cPB.hFileInfo.ioVRefNum = 0;
cPB.hFileInfo.ioFDirIndex = -1;
cPB.hFileInfo.ioDirID = cPB.dirInfo.ioDrParID;
err = PBGetCatInfoSync(&cPB);
strcpy(crt_defpath+1+*crt_defpath,tmp);
crt_defpath[0] = '/';
}
while ( /* (cPB.dirInfo.ioDrParID != 2) && */ !err);
}
char *getwd(char *fullname)
{
char *idx;
static char sfullname[256];
if (!*crt_defpath) macgetwd();
idx = index(crt_defpath+1, '/');
if (!idx) strcpy(sfullname, "/");
else strcpy(sfullname, idx);
if (fullname) strcpy(fullname, sfullname);
else fullname = sfullname;
return fullname;
}
char *mycanon(const char *nam)
{
char *dest;
static char path[256];
getwd(NULL);
strcpy(path, crt_defpath);
if (*nam != '/')
{
strcat(path,"/");
}
else
{
char *idx = index(path+1,'/');
if (idx) *idx = 0; else path[1] = 0;
}
strcat(path,nam);
dest = path;
while (*dest)
{
if (!strncmp(dest,"/..",3))
{
char *last;
*dest = 0;
last = rindex(path,'/');
if (last)
{
strcpy(last,dest+3);
dest = last;
}
else strcpy(dest,dest+3);
}
else if (!strncmp(dest,"/.",2))
{
strcpy(dest,dest+2);
}
else dest++;
}
return path;
}
StringPtr cnv_unix_name(const char *nam)
{
char *path = mycanon(nam);
char *dest = path;
while (*dest)
{
if (*dest == '/') *dest = ':';
dest++;
}
path[0] = strlen(path+1);
return (StringPtr)path;
}
int next_fd(int first)
{
int i;
for (i = first; i < OPEN_MAX; i++)
if (!crt_fd_tab[i].fd) return i;
}